﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace PLCS.App.Converts
{
    internal class IntToBoolConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is int intValue && parameter is string strParameter)
            {
                int targetValue;
                if (int.TryParse(strParameter, out targetValue))
                {
                    return intValue == targetValue;
                }
            }

            return false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool boolValue && parameter is string strParameter)
            {
                int targetValue;
                if (int.TryParse(strParameter, out targetValue))
                {
                    return boolValue ? targetValue : 1;
                }
            }

            return 0;
        }
    }
}